<?php

/**
 * @file
 * Provides example of multi forms for Emancipated Minor.
 */

/* Submits include */
module_load_include('inc', 'registration', '/mforms/registration.em_validates');
module_load_include('inc', 'registration', '/mforms/registration.em_submits');

function _register_em_pre_registration(&$form_state, &$next_step, $params) {
    $form = array();
    $form['title'] = array(
        '#markup' => t("<h2>Pre Registration</h2>"));
    
    $next_step = '_register_em_demographic_info';  

    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Continue'));

    $values = mforms_get_vals('em', '_register_em_pre_registration');
    
    
    $form['min_age'] = array(
        '#type' => 'radios',
        '#title' => t('Are you between the ages or 9-18?'),
        '#options' => array('yes' => t('Yes'), 'no' => t('No')),
        '#required' => TRUE,
    );
    
    $form['is_union_member'] = array(
        '#type' => 'radios',
        '#title' => t('Are you a member of an entertainment union?'),
        '#options' => array('yes' => t('Yes'), 'no' => t('No')),
        '#required' => TRUE,
    );
    
    $form['is_min_income'] = array(
        '#type' => 'radios',
        '#title' => t('Did you made $3000/yr for the last 2 years?'),
        '#options' => array('yes' => t('Yes'), 'no' => t('No')),
        '#required' => FALSE,
    );
    
    $form['have_agent'] = array(
        '#type' => 'radios',
        '#title' => t('Is your YP currently represented by an Agent or Manager?'),
        '#options' => array('yes' => t('Yes'), 'no' => t('No')),
        '#required' => TRUE,
    );
    return $form;
}
function _register_em_pre_registration_submit($form, &$form_state) {
    $vt_minAge = strtolower($form_state['values']["min_age"]);
    $vt_isUnionMember = strtolower($form_state['values']["is_union_member"]);
    $vt_minIncome = strtolower($form_state['values']["is_min_income"]);
    $vt_haveAgent = strtolower($form_state['values']["have_agent"]);

    $vb_OptimalAnswer = ($vt_minAge == "yes") && ($vt_haveAgent == "yes");

    if($vt_isUnionMember == "no"){
        $vb_OptimalAnswer = $vb_OptimalAnswer && ($vt_minIncome == "yes");
    }
    else{
        $vb_OptimalAnswer = $vb_OptimalAnswer && ($vt_isUnionMember == "yes");
    }
    
    //Set Error
    if(!$vb_OptimalAnswer){
        $steps = MformsSteps::getInstance(mforms_store_get('em'));
        $steps->overrideNext('_registration_em_reg_failed');
    }
}

/* FORM STEP : DEMOGRAPHIC INFO */
function _register_em_demographic_info(&$form_state, &$next_step, $params) {
    
    $form = array();
    $form['title'] = array(
        '#markup' => t("<h2>Demographic Information</h2>"));
    
    $next_step = '_register_em_address';
    
    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Next'));
    
    $form_key = "em_parents";
    
    //Set count of fields to show
    $form_state['storage'][$form_key] = isset($form_state['storage'][$form_key]) ? $form_state['storage'][$form_key] : -1;
    if(isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == "Remove Parent" &&       $form_state['storage'][$form_key] > 0){
        $form_state['storage'][$form_key]--;
    }
    else{
        $form_state['storage'][$form_key]++;
    }
    
    $form['msg'] = array(
        '#markup' => "Congratulations! Based on the criteria you selected, you may be eligible for the "
            . "Looking Ahead Program (subject to verification). Please continue to the enrollment forms to complete and submit. "
            . "If there are any questions, please contact (323) 933-9244 ext. 425".'<br/><br/>'
    );

    $form['first_name'] = array(
        '#type' => 'textfield',
        '#title' => t('Legal First Name'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['middle_name'] = array(
        '#type' => 'textfield',
        '#title' => t('Legal Middle Name'),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['last_name'] = array(
        '#type' => 'textfield',
        '#title' => t('Legal Last Name'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['aka_first_name'] = array(
        '#type' => 'textfield',
        '#title' => t('AKA First Name'),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['aka_last_name'] = array(
        '#type' => 'textfield',
        '#title' => t('AKA Last Name'),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['username'] = array(
        '#type' => 'textfield',
        '#title' => t('Username'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['email'] = array(
        '#type' => 'textfield',
        '#title' => t('Email'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['password'] = array(
        '#type' => 'password',
        '#title' => t('Password'),
        '#required' => TRUE,
    );
    $form['confirm_password'] = array(
        '#type' => 'password',
        '#title' => t('Confirm Password'),
        '#required' => TRUE,
    );
    $startYear=date('Y')-8;
    $form['dob'] = array(
        '#type' => 'date',
        '#title' => t('DOB'),
        '#start_year' => $startYear,
        '#required' => TRUE,
        '#process' => array('form_process_date', 'fix_em_dob_range'),
    );
    $form['cell_phone'] = array(
        '#type' => 'textfield',
        '#title' => t('Mobile #'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['phone_number'] = array(
        '#type' => 'textfield',
        '#title' => t('Phone # 2'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['marital_status'] = array(
        '#type' => 'select',
        '#options' => array(
            "" => t('Select'),
            1 => t('Single'),
            2 => t('Married'),
        ),
        '#title' => t('Marital Status'),
        '#default_value' => 'select',
        '#required' => TRUE,
    );
    $form['gender'] = array(
        '#type' => 'select',
        '#title' => t('Gender'),
        '#options' => array(
            "" => t('Select'),
            1 => t('Male'),
            2 => t('Female'),
        ),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['ethnicity'] = array(
        '#type' => 'select',
        '#title' => t('Ethnicity'),
        '#options' => returnEthnicity(),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['alternate_contact'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Alternate Method(s) of Contact (other than email)'),
        '#options' => returnContactMethods(),
        '#default_value' => array(),
        '#required' => TRUE,
    );
    $form['text_carrier'] = array(
        '#type' => 'select',
        '#title' => t('Add Carrier for Text'),
        '#options' => drupal_map_assoc(array(t('Carrier 1'), t('Carrier 2'))),
        '#default_value' => array(),
        '#required' => FALSE,
    );
    $form['ca_resident'] = array(
        '#type' => 'radios',
        '#title' => t('CA Resident?'),
        '#options' => array(0 => t('No'), 1 => t('Yes')),
        '#default_value' => array(),
        '#required' => TRUE,
    );
        
    $form[$form_key] = array(
        '#type' => 'container',
        '#tree' => TRUE,
        '#prefix' => '<div id="'. $form_key .'">',
        '#suffix' => '</div>',
    );
    
    //Add Parent Form
    for ($i = 0; $i < $form_state['storage'][$form_key]; $i++){
        //$i = 0;
        $form[$form_key][$i] = array(
            '#type' => 'fieldset',
            '#title' => t('Parent Info'),
            '#tree' => TRUE,
        );
        
        $form[$form_key][$i]['f_name'] = array(
            '#type' => 'textfield',
            '#title' => t('First Name'),
            '#default_value' => '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['mid_name'] = array(
            '#type' => 'textfield',
            '#title' => t('Middle Name'),
            '#default_value' => '',
            '#required' => FALSE,
        );

        $form[$form_key][$i]['surname'] = array(
            '#type' => 'textfield',
            '#title' => t('Last Name'),
            '#default_value' =>'',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['username'] = array(
            '#type' => 'textfield',
            '#title' => t('Username'),
            '#default_value' => '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['email'] = array(
            '#type' => 'textfield',
            '#title' => t('Email'),
            '#default_value' => '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['password'] = array(
            '#type' => 'password',
            '#title' => t('Password'),
            '#required' => TRUE,
        );

        $form[$form_key][$i]['confirm_password'] = array(
            '#type' => 'password',
            '#title' => t('Confirm Password'),
            '#required' => TRUE,
        );

        $form[$form_key][$i]['dob'] = array(
            '#type' => 'date',
            '#title' => t('DOB'),
            '#default_value' => "",
            '#required' => TRUE,
        );

        $form[$form_key][$i]['phone_1'] = array(
            '#type' => 'textfield',
            '#title' => t('Mobile #'),
            '#default_value' => "",
            '#required' => TRUE,
        );

        $form[$form_key][$i]['phone_2'] = array(
            '#type' => 'textfield',
            '#title' => t('Phone # 2'),
            '#default_value' =>  '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['marital_status'] = array(
            '#type' => 'select',
            '#options' => array(
                0 => t('Select'),
                1 => t('Single'),
                2 => t('Married'),
            ),
            '#title' => t('Marital Status'),
            '#default_value' => '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['gender'] = array(
            '#type' => 'select',
            '#title' => t('Gender'),
            '#options' => array(
                0 => t('Select'),
                1 => t('Male'),
                2 => t('Female'),
            ),
            '#default_value' => '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['ethnicity'] = array(
            '#type' => 'select',
            '#title' => t('Ethnicity'),
            '#options' => returnEthnicity(),
            '#default_value' =>  '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['alternate_contact'] = array(
            '#type' => 'checkboxes',
            '#title' => t('Alternate Method(s) of Contact (other than email)'),
            '#options' => drupal_map_assoc(array(t('Postal Mail'), t('Text Messages'))),
            '#default_value' => array(),
            '#required' => TRUE,
        );
        
        $form[$form_key][$i]['text_carrier'] = array(
            '#type' => 'select',
            '#title' => t('Add Carrier for Text'),
            '#options' => drupal_map_assoc(array(t('Carrier 1'), t('Carrier 2'))),
            '#default_value' => array(),
            '#required' => FALSE,
        );

        $form[$form_key][$i]['ca_resident'] = array(
            '#type' => 'radios',
            '#title' => t('CA Resident?'),
            '#options' => drupal_map_assoc(array(t('Yes'), t('No'))),
            '#default_value' => array(),
            '#required' => TRUE,
        );
    }
    
    $form[$form_key]['add_parent'] = array(
        '#type' => 'button',
        '#href' => '',
        '#title' => t('Add Parent'),
        '#default_value' => t('Add Parent'),
        '#name' => t('Add Parent'),
        '#limit_validation_errors' => array(),
        '#executes_submit_callback' => FALSE,
        '#ajax' => array(
          'callback' => '_register_em_add_parent',
          'wrapper' => $form_key,
          'effect' => 'fade',
        ),
    );
    if($form_state['storage'][$form_key] > 0){
        $form[$form_key]['remove_parent'] = array(
            '#type' => 'button',
            '#href' => '',
            '#title' => t('Remove Parent'),
            '#default_value' => t('Remove Parent'),
            '#name' => t('Remove Parent'),
            '#limit_validation_errors' => array(),
            '#executes_submit_callback' => FALSE,
            '#ajax' => array(
              'callback' => '_register_em_add_parent',
              'wrapper' => $form_key,
              'effect' => 'fade',
            ),
        ); 
    }
    return $form;
}
function _register_em_add_parent($form, &$form_state){
    return $form['em_parents'];
}

/* FORM STEP : ADDRESS INFO */
function _register_em_address(&$form_state, &$next_step, $params){
    $form = array();
    $form['title'] = array(
        '#markup' => t("<h2>Address</h2>"));
    
    $next_step = '_register_em_eligibility';
    
    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Next'));
    
    $states = getStates();
    
    $form_key = "em_addresses";
    
    //Set count of fields to show
    $form_state['storage'][$form_key] = isset($form_state['storage'][$form_key]) ? $form_state['storage'][$form_key] : 0;
    if(isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == "Remove Address" && $form_state['storage'][$form_key] > 0){
        $form_state['storage'][$form_key]--;
    }
    else{
        $form_state['storage'][$form_key]++ ;
        if($form_state['storage'][$form_key] > 2){
            $form_state['storage'][$form_key] = 2;
        }
    }
    
     $form[$form_key] = array(
        '#type' => 'container',
        '#tree' => TRUE,
        '#prefix' => '<div id="'. $form_key .'">',
        '#suffix' => '</div>',
    );
    
    for ($i = 0; $i < $form_state['storage'][$form_key]; $i++) {
        $form[$form_key][$i] = array(
            '#type' => 'fieldset',
            '#tree' => TRUE,
        );
        
        $form[$form_key][$i]['mailing_address'] = array(
            '#type' => 'textfield',
            '#title' => t( ($i == 0) ? 'Primary Mailing Address' : 'Secondary Mailing Address'),
            '#default_value' => '',
            '#required' => TRUE,
        );
        $form[$form_key][$i]['apt_no'] = array(
            '#type' => 'textfield',
            '#title' => t('APT #'),
            '#default_value' => '',
            '#required' => FALSE,
        );
        $form[$form_key][$i]['city'] = array(
            '#type' => 'textfield',
            '#title' => t('City'),
            '#default_value' => '',
            '#required' => TRUE,
        );

        $form[$form_key][$i]['state'] = array(
            '#type' => 'select',
            '#title' => t('State'),
            '#options' => $states,
            '#default_value' => 'CA',
            '#required' => TRUE,
        );
        $form[$form_key][$i]['zip'] = array(
            '#type' => 'textfield',
            '#title' => t('Zip'),
            '#default_value' => '',
            '#required' => TRUE,
            '#element_validate' => array('element_validate_integer_positive'),
        );
        $form[$form_key][$i]['no_of_adults_address'] = array(
            '#type' => 'textfield',
            '#title' => t('# of adults at this address'),
            '#default_value' => '',
            '#element_validate' => array('element_validate_number'),
            '#required' => TRUE,
        );
        $form[$form_key][$i]['no_of_children_address'] = array(
            '#type' => 'textfield',
            '#title' => t('# of children at this address'),
            '#default_value' => '',
            '#element_validate' => array('element_validate_number'),
            '#required' => TRUE,
        );
        $form[$form_key][$i]['mail_at_address'] = array(
            '#type' => 'radios',
            '#title' => t('Do you want mailings at this address'),
            '#options' => array(0 => t('No'), 1 => t('Yes')),
            '#default_value' => array(),
            '#required' => TRUE,
        );
    }
    if($form_state['storage'][$form_key] < 2){
        $form[$form_key]['add_address'] = array(
           '#type' => 'button',
           '#href' => '',
           '#title' => t('Add Address'),
           '#default_value' => t('Add Secondary Address'),
           '#name' => t('Add Address'),
           '#limit_validation_errors' => array(),
           '#executes_submit_callback' => FALSE,
           '#ajax' => array(
              'callback' => '_register_em_load_addresses',
              'wrapper' => $form_key,
              'effect' => 'fade',
           ),
    );
    }
    if($form_state['storage'][$form_key] > 1){
        $form[$form_key]['remove_address'] = array(
            '#type' => 'button',
            '#href' => '',
            '#title' => t('Remove Address'),
            '#default_value' => t('Remove Secondary Address'),
            '#name' => t('Remove Address'),
            '#limit_validation_errors' => array(),
            '#executes_submit_callback' => FALSE,
            '#ajax' => array(
              'callback' => '_register_em_load_addresses',
              'wrapper' => $form_key,
              'effect' => 'fade',
            ),
        ); 
    }
    
    $form['save_draft'] = array(
            '#type' => 'button',
            '#href' => '',
            '#title' => t('Save Draft'),
            '#default_value' => t('Save Draft'),
            '#name' => t('Save Draft'),
            '#limit_validation_errors' => array(),
            '#executes_submit_callback' => FALSE);
    return $form;
}
function _register_em_load_addresses($form, &$form_state) {
    return $form['em_addresses'];
}     


/* FORM STEP : ELIGIBILITY INFO */
function _register_em_eligibility(&$form_state, &$next_step, $params){
    $form = array();
    $form['title'] = array(
        '#markup' => t("<h2>Eligibility</h2>"));
    
    $next_step = '_register_em_education';

    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Next'));

    $unions = returnUnions();
    $form_key = "em_unions";
    
    //Set count of fields to show
    $form_state['storage'][$form_key] = isset($form_state['storage'][$form_key]) ? $form_state['storage'][$form_key] : 0;
    if(isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == "Remove Union" && $form_state['storage'][$form_key] > 0){
        $form_state['storage'][$form_key]--;
    }
    else{
        $form_state['storage'][$form_key]++;
    }
    
    $form[$form_key] = array(
        '#type' => 'container',
        '#tree' => TRUE,
        '#prefix' => '<div id="'. $form_key .'">',
        '#suffix' => '</div>',
    );
    
    if ($form_state['storage'][$form_key]) {
        for ($i = 0; $i < $form_state['storage'][$form_key]; $i++) {
            $form[$form_key][$i] = array(
                '#type' => 'fieldset',
                '#title' => t('Union'),
                '#tree' => TRUE,
            );
            
            $form[$form_key][$i]["union_id"] = array(
                '#type' => 'select',
                '#title' => t('Union'),
                '#options' => $unions,
                '#required' => TRUE,
            );
            $form[$form_key][$i]["union_no"] = array(
                '#type' => 'textfield',
                '#title' => t('Union #'),
                '#required' => TRUE,
            );
        }
    }
    
    $form[$form_key]['add_union'] = array(
        '#type' => 'button',
        '#href' => '',
        '#title' => t('Add Union'),
        '#default_value' => t('Add Union'),
        '#name' => t('Add Union'),
        '#limit_validation_errors' => array(),
        '#executes_submit_callback' => FALSE,
        '#ajax' => array(
          'callback' => '_register_em_load_unions',
          'wrapper' => $form_key,
          'effect' => 'fade',
        ),
    );
    if($form_state['storage'][$form_key] > 1){
        $form[$form_key]['remove_union'] = array(
            '#type' => 'button',
            '#href' => '',
            '#title' => t('Remove Union'),
            '#default_value' => t('Remove Union'),
            '#name' => t('Remove Union'),
            '#limit_validation_errors' => array(),
            '#executes_submit_callback' => FALSE,
            '#ajax' => array(
              'callback' => '_register_em_load_unions',
              'wrapper' => $form_key,
              'effect' => 'fade',
            ),
        ); 
    }
    
    $form['agency'] = array(
        '#type' => 'textfield',
        '#title' => t('Agency'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['agent_name'] = array(
        '#type' => 'textfield',
        '#title' => t('Agent Name'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['agent_phone'] = array(
        '#type' => 'textfield',
        '#title' => t('Agency Phone'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['non_union_docs'] = array(
        '#type' => 'file',
        '#title' => t('Upload non-union docs'),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['save_draft'] = array(
        '#type' => 'button',
        '#href' => '',
        '#title' => t('Save Draft'),
        '#default_value' => t('Save Draft'),
        '#name' => t('Save Draft'),
        '#limit_validation_errors' => array(),
        '#executes_submit_callback' => FALSE);
    return $form;
}
function _register_em_load_unions($form, &$form_state) {
    return $form['em_unions'];
}

/* FORM STEP : EDUCATION INFO */
function _register_em_education(&$form_state, &$next_step, $params){
    $form = array();
    $form['title'] = array(
        '#markup' => t("<h2>Education</h2>"));
    
    $next_step = '_register_em_waivers_releases';
    
    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Next'));
    $form_key = "em_schools";
    
    $states = getStates();
    
    //Set no of schools to display
    $form_state['storage'][$form_key] = isset($form_state['storage'][$form_key]) ? $form_state['storage'][$form_key] : 0;
    if(isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == "Remove School" && $form_state['storage'][$form_key] > 0){
        $form_state['storage'][$form_key]--;
    }
    else{
        $form_state['storage'][$form_key]++;
    }
    
    $form[$form_key] = array(
        '#type' => 'container',
        '#tree' => TRUE,
        '#prefix' => '<div id="'. $form_key .'">',
        '#suffix' => '</div>',
    );
    
    for ($i = 0; $i < $form_state['storage'][$form_key]; $i++) {
        $form[$form_key][$i] = array(
            '#type' => 'fieldset',
            '#title' => t('School'),
            '#tree' => TRUE,
        );

        $form[$form_key][$i]['school_name'] = array(
            '#type' => 'textfield',
            '#title' => t('Name of school'),
            '#default_value' => '',
            '#required' => TRUE,
        );
        $form[$form_key][$i]['school_city'] = array(
            '#type' => 'textfield',
            '#title' => t('City'),
            '#default_value' => '',
            '#required' => TRUE,
        );
        $form[$form_key][$i]['school_state'] = array(
            '#type' => 'select',
            '#title' => t('State'),
            '#options' => $states,
            '#default_value' => 'CA',
            '#required' => TRUE,
        );
        $form[$form_key][$i]['school_zip'] = array(
            '#type' => 'textfield',
            '#title' => t('Zip'),
            '#default_value' => '',
            '#required' => TRUE,
            '#element_validate' => array('element_validate_integer_positive'),
        );
        $form[$form_key][$i]['school_type'] = array(
            '#type' => 'select',
            '#title' => t('Type'),
            '#options' => array(''=>'Select','php' => t('Type 1'), 'css' => t('Type 2'), ),
            '#default_value' => array(),
            '#required' => TRUE,
        );
        $form[$form_key][$i]['school_years'] = array(
            '#type' => 'textfield',
            '#title' => t('Years at school'),
            '#default_value' => '',
            '#required' => TRUE,
            '#element_validate' => array('element_validate_integer_positive'),
        );
        $form[$form_key][$i]['school_grade_level'] = array(
            '#type' => 'textfield',
            '#title' => t('Grade Level'),
            '#default_value' => '',
            '#required' => TRUE,
        );
        $form[$form_key][$i]['has_graduated'] = array(
            '#type' => 'radios',
            '#title' => t('Graduated'),
            '#options' => array(1 => t('Yes'), 0 => t('No')),
            '#default_value' => array(),
            '#required' => TRUE,
        );
    }
    
    $form[$form_key]['add_school'] = array(
        '#type' => 'button',
        '#href' => '',
        '#title' => t('Add School'),
        '#default_value' => t('Add School'),
        '#name' => t('Add School'),
        '#limit_validation_errors' => array(),
        '#executes_submit_callback' => FALSE,
        '#ajax' => array(
          'callback' => '_register_em_add_school',
          'wrapper' => $form_key,
          'effect' => 'fade',
        ),
    );
    if($form_state['storage'][$form_key] > 1){
        $form[$form_key]['remove_school'] = array(
            '#type' => 'button',
            '#href' => '',
            '#title' => t('Remove School'),
            '#default_value' => t('Remove School'),
            '#name' => t('Remove School'),
            '#limit_validation_errors' => array(),
            '#executes_submit_callback' => FALSE,
            '#ajax' => array(
              'callback' => '_register_em_add_school',
              'wrapper' => $form_key,
              'effect' => 'fade',
            ),
        ); 
    }
    $form['save_draft'] = array(
        '#type' => 'button',
        '#href' => '',
        '#title' => t('Save Draft'),
        '#default_value' => t('Save Draft'),
        '#name' => t('Save Draft'),
        '#limit_validation_errors' => array(),
        '#executes_submit_callback' => FALSE);
    return $form;
}
function _register_em_add_school($form, &$form_state) {
    return $form['em_schools'];
}

/* FORM STEP : Waivers AND RELEASES INF0 */
function _register_em_waivers_releases(&$form_state, &$next_step, $params){
    $form = array();
    $form['title'] = array(
        '#markup' => t("<h2>Waivers and Releases</h2>"));
    
    $next_step = '_register_em_additional_info';
    
    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Next'));
    $form_key = "em_waivers_releases";
    
    $states = getStates();
    
    $form['code_of_conduct'] = array(
        '#type' => 'checkbox',
        '#title' => t('Code of Conduct'),
        '#default_value' => "",
        '#required' => TRUE,
    );
    $form['photo_release'] = array(
        '#type' => 'checkbox',
        '#title' => t('Photo Release'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['video_release'] = array(
        '#type' => 'checkbox',
        '#title' => t('Video Release'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact'] = array(
            '#type' => 'fieldset',
            '#title' => t('Emergency Contact'),
            '#tree' => TRUE,
    );
    $form['emergency_contact']['emergency_contact_first'] = array(
        '#type' => 'textfield',
        '#title' => t('First Name'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact']['emergency_contact_last'] = array(
        '#type' => 'textfield',
        '#title' => t('Last Name'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact']['emergency_phone'] = array(
        '#type' => 'textfield',
        '#title' => t('Phone'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact']['emergency_address'] = array(
        '#type' => 'textfield',
        '#title' => t('Address'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact']['emergency_apt'] = array(
        '#type' => 'textfield',
        '#title' => t('APT'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact']['emergency_city'] = array(
        '#type' => 'textfield',
        '#title' => t('City'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact']['emergency_state'] = array(
        '#type' => 'select',
        '#title' => t('State'),
        '#options' => $states,
        '#default_value' => 'CA',
        '#required' => TRUE,
    );
    $form['emergency_contact']['emergency_zip'] = array(
        '#type' => 'textfield',
        '#title' => t('Zip'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['emergency_contact']['relationship_to_participant'] = array(
        '#type' => 'textfield',
        '#title' => t('Relationship to Participant'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['name_of_insurance'] = array(
        '#type' => 'textfield',
        '#title' => t('Name of Insurance'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['medical_insurance_no'] = array(
        '#type' => 'textfield',
        '#title' => t('Medical Insurance#'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['disabilities'] = array(
        '#type' => 'radios',
        '#options' => array( 1 => t('Yes'), 0 => t('No')),
        '#title' => t('Disabilities, Ailments, Needs, Treatments? '),
        '#default_value' => array(),
        '#required' => TRUE,
    );
    $form['disability_explanation'] = array(
        '#type' => 'textarea',
        '#title' => t('Disability Explanation'),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['medication_allergy'] = array(
        '#type' => 'radios',
        '#options' => array( 1 => t('Yes'), 0 => t('No')),
        '#title' => t('Allergic to any medication or anything else?'),
        '#default_value' => array(),
        '#required' => TRUE,
    );
    $form['allergy_explanation'] = array(
        '#type' => 'textarea',
        '#title' => t('Allergy Explanation'),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['taking_medication'] = array(
        '#type' => 'radios',
        '#options' => array( 1 => t('Yes'), 0 => t('No')),
        '#title' => t('Taking any medication?'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['medication_explanation'] = array(
        '#type' => 'textarea',
        '#title' => t('Medication Explanation'),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['digital_signature'] = array(
        '#type' => 'textfield',
        '#title' => t('Digital Signature'),
        '#default_value' => '',
        '#required' => TRUE,
    );
    $form['digital_date_stamp'] = array(
        '#type' => 'textfield',
        '#title' => t('Digital Date Stamp'),
        '#default_value' => format_date(time(), 'custom', 'l j F Y'),
        '#required' => TRUE,
    );
    
    
    $form['save_draft'] = array(
            '#type' => 'button',
            '#href' => '',
            '#title' => t('Save Draft'),
            '#default_value' => t('Save Draft'),
            '#name' => t('Save Draft'),
            '#limit_validation_errors' => array(),
            '#executes_submit_callback' => FALSE);
    return $form;
}

/* FORM STEP : ADDITIONAL INF0 */
function _register_em_additional_info(&$form_state, &$next_step, $params){
    $form = array();
    $form['title'] = array(
        '#markup' => t("<h2>Additional Information</h2>"));
    
    $next_step = '_registration_em_reg_success';
    
    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Finish'));
    
    $form['more_info'] = array(
        '#type' => 'radios',
        '#title' => t('Would you like for staff to contact you with more info on the Looking Ahead Program?'),
        '#options' => array(1 => 'Yes', 0 => t('No')),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['education_counseling'] = array(
        '#type' => 'radios',
        '#title' => t('Are you interested in a phone or in-person appt for Educational Counseling?'),
        '#options' => array(1 => 'Yes', 0 => t('No')),
        '#default_value' => '',
        '#required' => FALSE,
    );
    $form['family_counseling'] = array(
        '#type' => 'radios',
        '#title' => t('Are you interested in a phone or in-person appt for Family/Individual Counseling?'),
        '#options' => array(1 => 'Yes', 0 => t('No')),
        '#default_value' =>'',
        '#required' => FALSE,
    );
    $form['heard_from'] = array(
        '#type' => 'checkboxes',
        '#title' => t('How did you hear about us?'),
        '#options' => array('Google' => t('Google'), 'Friend' => t('Friend')),
        '#default_value' => array(),
        '#required' => FALSE,
    );
    $form['save_draft'] = array(
            '#type' => 'button',
            '#href' => '',
            '#title' => t('Save Draft'),
            '#default_value' => t('Save Draft'),
            '#name' => t('Save Draft'),
            '#limit_validation_errors' => array(),
            '#executes_submit_callback' => FALSE);
    return $form;
}

function _registration_em_reg_success(&$form_state, &$next_step, $params) {
    
    drupal_set_message("Registration Successful. Please Log into your new created account to start using Looking Ahead Services.");
    $form = array();
    $form["submit"] = null;
    mforms_clean("em");
    return $form;
}

function _registration_em_reg_failed(&$form_state, &$next_step, $params) {
    $controls = mforms_controls_get('em');
    $controls->setControlsLabels(t('Back'), t("Continue"));
    $controls->setCancelPath("register/em");
  
    $form = array();
    $form['error_text'] = array(
        '#type'=>'markup',
        '#markup'=>t('Thank you for your interest in the Looking Ahead Program for Young Performers. '
            . 'Based on the information provided, you may not be eligible at this time. Please contact us at '
            . '(323) 933-9244 ext. 425 to talk with our staff and discuss your unique circumstances <br />'),
        '#weight' => 35,
     );  
    return $form;
}

function _registration_em_reg_failed_submit($form, &$form_state) {
    $form_state['values']["next_step"] = "_registration_em_pre_registration";
    mforms_clean("em");
}